package com.example.demo.utils;

import org.springframework.util.ReflectionUtils;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;
public class EntityMapUtils {

    public static Map<String, Object> entityToMap(Object object) {
        Map<String, Object> map = new HashMap<>();
        for (Field field : object.getClass().getDeclaredFields()) {
            try {
                boolean flag = field.isAccessible();
                //field.setAccessible(true);
                ReflectionUtils.makeAccessible(field);
                Object o = field.get(object);
                map.put(field.getName(), o);
                field.setAccessible(flag);
            } catch (Exception e) {
                LoggerUtils.log( "entitymap", e);
            }
        }
        return map;
    }

}